package br.usp.ime.protoc.neuroimagem;

import java.util.HashSet;
import java.util.Iterator;

import com.google.gwt.user.client.rpc.IsSerializable;

import br.usp.ime.protoc.fujaba.FEmptyIterator;

public class Sequencia implements IsSerializable
{
   /**
    * <pre>
    *            1          has           1..* 
    * Sequencia ------------------------------- Intercorrencia
    *            sequencia      intercorrencia 
    * </pre>
    */
   private HashSet intercorrencia;

   public boolean addToIntercorrencia(Intercorrencia value)
   {
      boolean changed = false;
      if (value != null)
      {
         if (this.intercorrencia == null)
         {
            this.intercorrencia = new HashSet (); // or FTreeSet () or FLinkedList ()
         }
         
         changed = this.intercorrencia.add (value);
         if (changed)
         {
            value.setSequencia (this);
         }
         
      }
      return changed;
   }

   public boolean hasInIntercorrencia(Intercorrencia value)
   {
      return ((this.intercorrencia != null) &&
              (value != null) &&
              this.intercorrencia.contains (value));
   }

   public Iterator iteratorOfIntercorrencia()
   {
      return ((this.intercorrencia == null)
              ? FEmptyIterator.get ()
              : this.intercorrencia.iterator ());
   }

   public void removeAllFromIntercorrencia()
   {
      Intercorrencia tmpValue;
      Iterator iter = this.iteratorOfIntercorrencia ();
      while (iter.hasNext ())
      {
         tmpValue = (Intercorrencia) iter.next ();
         this.removeFromIntercorrencia (tmpValue);
      }
   }

   public boolean removeFromIntercorrencia(Intercorrencia value)
   {
      boolean changed = false;
      if ((this.intercorrencia != null) && (value != null))
      {
         
         changed = this.intercorrencia.remove (value);
         if (changed)
         {
            value.setSequencia (null);
         }
         
      }
      return changed;
   }

   public int sizeOfIntercorrencia()
   {
      return ((this.intercorrencia == null)
              ? 0
              : this.intercorrencia.size ());
   }

   public void removeYou()
   {
      removeAllFromIntercorrencia ();
   }

}
